﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using Confucius.utils;
using Confucius.entity;
using Confucius.daoImpl;
using System.Windows.Media.Imaging;

namespace Confucius.pages
{
    public partial class GameInfoPage : PhoneApplicationPage
    {
        private Game currentGame;

        public GameInfoPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(InfoPage_Loaded);
        }

        private void InfoPage_Loaded(object sender, RoutedEventArgs e)
        {
            String gameID = "";
            if (IsolatedStorageSettings.ApplicationSettings.Contains(Constants.CURRENT_GAMEID))
            {
                gameID = (string)IsolatedStorageSettings.ApplicationSettings[Constants.CURRENT_GAMEID];
            }
            if (gameID == "")
            {
                gameID = "8712da1d-cf94-48d4-bcde-76be37963f2b";
                //NavigationService.GoBack();
            }

            currentGame = new GameDAOImpl(Application.Current as App).readGameDetail(gameID);
            GameName.Text = currentGame.PublishTitle;

            string[] coverIDString = currentGame.GameCoverID.Split('.');
            if (coverIDString.Length < 2)
            {
                Uri uri = ConfuciusUtil.buildImageUri(gameID, currentGame.GameCoverID);
                GameCover.Source = new BitmapImage(uri);
            }
            else
            {
                Uri uri = ConfuciusUtil.buildImageUriWithExtension(gameID, currentGame.GameCoverID);
                GameCover.Source = new BitmapImage(uri);
            }
            GameIntro.Text = currentGame.Introduction;
            GameAuthor.Text = currentGame.Author;
            GameEmail.Text = currentGame.Email;
            GameAgent.Text = currentGame.PublishAgent;
        }
    }
}